﻿$(function () {
    $("#cname").blur(function () {
        if ($("#cname").val() == "") {
            $("#spCname").html("<img src=\"/cn/images/wrong.gif\" /> 请输入收货人姓名！");
        }
        else $("#spCname").html("<img src=\"/cn/images/right.gif\"/>");
        return false;
    });
    $("#phone").blur(function () {
        if ($("#phone").val() == "" && $("#tel").val() == "") {
            $("#spTel").html("<img src=\"/cn/images/wrong.gif\" /> 联系电话与手机致少填一项！");
        }
        else $("#spTel").html("<img src=\"/cn/images/right.gif\"/>");
        return false;
    });

    $("#ddlProvence").blur(function () {

        if ($("#ddlProvence").val() == "") {
            $("#spAddress").html("<img src=\"/cn/images/wrong.gif\" /> 请选择省！");
        }

        return false;
    });

    $("#ddlCity").blur(function () {

        if ($("#ddlCity").val() == "") {
            $("#spAddress").html("<img src=\"/cn/images/wrong.gif\" /> 请选择地区！");
        }

        return false;
    });

    $("#address").blur(function () {

        if ($("#address").val() == "") {
            $("#spAddress").html("<img src=\"/cn/images/wrong.gif\" /> 地址不能为空！");
        }

        return false;
    });


    $("#btnSubmit").click(function () {

        var isValidate = true;
        var addressMessage = "";
        if ($("#cname").val() == "") {
            $("#spCname").html("<img src=\"/cn/images/wrong.gif\" /> 请输入收货人姓名！");
            isValidate = false;
        }
        else $("#spCname").html("<img src=\"/cn/images/right.gif\"/>");

        if ($("#phone").val() == "" && $("#tel").val() == "") {
            $("#spTel").html("<img src=\"/cn/images/wrong.gif\" /> 联系电话与手机致少填一项！");
            isValidate = false;
        }
        else $("#spTel").html("<img src=\"/cn/images/right.gif\"/>");



        if ($("#ddlProvence").val() == "") {
            isValidate = false;
            addressMessage = addressMessage + "请选择省！";
        }



        if ($("#ddlCity").val() == "选择地区") {
            isValidate = false;
            addressMessage = addressMessage + "请选择地区！";
        }


        if ($("#address").val() == "") {
            isValidate = false;
            addressMessage = addressMessage + "地址不能为空！";
        }

        if (addressMessage == "") {
            $("#spAddress").html("<img src=\"/cn/images/right.gif\"/>");
        } else {
            $("#spAddress").html("<img src=\"/cn/images/wrong.gif\" />" + addressMessage);
        }

        if (isValidate == false) {
            return false;
        }

        $.ajax({
            type: "POST",
            url: "/orderSubmitHandler.ashx",
            data: "cname=" + escape($("#cname").val()) + "&tel=" + escape($("#tel").val()) + "&phone=" + escape($("#phone").val()) + "&ordercode=" + escape($("#ordercode").val())
                        + "&post=" + escape($("#post").val()) + "&email=" + escape($("#email").val()) + "&senddate=" + escape($("#senddate").val())
                         + "&provence=" + escape($("#ddlProvence").val()) + "&area=" + escape($("#ddlArea").val()) + "&address=" + escape($("#address").val())
            ,
            success: function (msg) {


                if (msg == "101") {
                    art.dialog.tips("操作时间过期，请重新登录购买！", 5);
                }
                else if (msg == "102") {
                    art.dialog.tips("请输入卡后进行兑换！", 10);
                }
                else if (msg == "103") {
                    art.dialog.tips("所选商品福点数与提货卡内福点数不一致，请重新选择商品！", 10);
                }
                else if (msg == "104") {
                    art.dialog.tips("该卡片无法兑换商品，请与客服联系！", 10);
                }
                else if (msg == "105") {
                    art.dialog.tips("不可以同时提交不同类商品，请先删除一类商品，然后提交！", 10);
                }
                else if (msg == "107") {
                    art.dialog.tips("账户内福点数不够支付您选购的商品，请重新选择商品，或者请先购买福点！", 10);
                }
                else if (msg == "109") {
                    art.dialog.tips("账户内福点数不够支付您选购的商品与运费，商品(不包含卡券)总价低于200个福点的，要收取10个福点运费，请重新选择商品，或者请先购买福点！", 10);
                }
                else if (msg == "108") {
                    art.dialog.tips("恭喜您，下单成功！", 3);
                    window.location.href = "order.aspx?code=" + escape($("#ordercode").val())

                } else {
                    art.dialog.tips(msg, 10);
                }
            }
        });
        return false;
    });



    $("#btnLoginSubmit").click(function () {

      TB_show(null, "/cn/login.aspx?TB_iframe=true&height=370&width=640", false);
      
    });




});
